package com.yanggu.scala.chapater14

object RecursiveDemo02 {

  def main(args: Array[String]): Unit = {
    // 递归的方式来解决
    def mx(num: BigInt, sum: BigInt): BigInt = {
      if (num <= 99999999L)
        mx(num + 1, sum + num)
      else
        sum
    }

    //测试
    var num = BigInt(1)
    var sum = BigInt(0)
    val now = System.currentTimeMillis()
    var res = mx(num, sum)
    println("res=" + res)
    printf(s"总共耗时${System.currentTimeMillis() - now}毫秒")

  }

}
